<template>
	<!--POP画册、POP下单、道具下单-->
	<view class="page-content">
		<view class="page-top">
			<!-- 标题栏和状态栏占位符 -->
			<view class="titleNview-placing"></view>
			<!-- 标题+筛选 -->
			<w-sel-search topType="two" :col_num="4" label_height="52" :pageobj="pageobj" popHeight="630"
				leftIcon="arrowleft" :cenTit="page_title" cenType="title" iconfont="28" :is_back="false" @back="back"
				@resetFilterData="resetFilterData" @selectRadioLabel="selectRadioLabel" @setFilterData="setFilterData">
			</w-sel-search>
		</view>
		<scroll-view class="page-body" :scroll-top="scrollTop" scroll-y="true" @scrolltolower="loadmore()">
			<!--产品图片数据-->
			<template v-if="objdata.objlist && objdata.objlist.length > 0 ">
				<view class="body-box">
					<product-num-edit :obj="objdata.objlist" :list2="list2" @delItem="delItem" :is_edit="false"
						:delBtnWidth="0" @delItem2="delItem2" @checks="checks" @edit_remark="edit_remark"
						@choose="choose" @confirm="confirm_sel" @add_pro="add_pro" @add_pro2="add_pro2"
					 @rednum2="rednum2" @rednum1="rednum1" @addnum2="addnum2" @addnum1="addnum1"
						:pageType="pageType">
					</product-num-edit>
				</view>
				<view class="btn-box">
					<view class="submit" @tap="confirm()">下一步</view>
				</view>
				<!-- 上拉加载 -->
				<view class="det-con-more">
					<load-more :loadmore="load_more1"></load-more>
				</view>
			</template>
			<!--无数据-->
			<empty v-else no-full type="noData"></empty>
		</scroll-view>
		<w-popup :show="showtip" :type="type1" @change="change1">
			<view class="w-tip">
				<view class="w-con">
					<view class="w-con-txt" v-if="pageType==='pop'" @click="toPop">POP画册</view>
					<view class="w-con-txt" @click="photoAlbum">手机相册</view>
					<view class="w-con-cen" @click="cancel('tip')">取消</view>
				</view>
			</view>
		</w-popup>
		<w-popup :show="showtip2" :type="type1" @change="change1">
			<view class="w-tip3">
				<view class="w-con">
					<view class="w-con-txt" v-if="pageType==='pop'" @click="toPop2">POP画册</view>
					<view class="w-con-cen" @click="cancel('tip2')">取消</view>
				</view>
			</view>
		</w-popup>
		<!--编辑框-->
		<w-popup :show="showinput" :type="type1" @change="change1">
			<view class="w-tip2">
				<view class="w-tit">{{popType==='1'?'备注':'提示'}}</view>
				<view class="w-con">
					<input class="txt-input" v-if="popType==='1'" type="text" v-model="mark" placeholder="请输入备注"
						placeholder-style="color:#bbb;font-size:26rpx"></input>
					<view class="txt-row" v-else="popType==='2'">是否删除？</view>
				</view>
				<view class="w-but">
					<view class="w-but-txt" @click="cancel('tip')">取消</view>
					<view class="w-but-txt" @click="confirm2">确认</view>
				</view>
			</view>
		</w-popup>
	</view>
</template>

<script>
	import wSelSearch from '@/components/w-sel-logo/w-sel-search.vue'; //标题
	import loadMore from '@/components/uni-load-more/load-more.vue';
	import productNumEdit from '@/pages/components/product_num_edit2.vue';
	import wPopup from '@/components/w-popup/w-popup2.vue';
	import {
		mapGetters,
		mapActions
	} from "vuex";
	import {
		taskDataInfos, //获取任务详情
		getFlowLists, //获取流程
		getProductCodingLists, //pop列表
		saveTaskDatas, //保存
		editTasks, //编辑流程
		getOssUploadsParams,
		getProductAttrLists, //获取产品属性列表

	} from '@/common/api.js';
	export default {
		components: {
			loadMore,
			productNumEdit,
			wSelSearch,
			wPopup
		},
		data() {
			return {
				page_title: '',
				pageobj: {
					name: '单选',
					type: 'radio',
					submenu: []
				},
				scrollTop: 0,
				noData: false,
				load_more1: '', //下拉加载文字
				load_sta: false, //是否是加载状态
				page_title: '',
				objdata: {
					id: 1,
					image: '/static/data-img/img.jpg',
					title: '任务名任务名任务名任务名',
					flowname: '',
					datalist: [],
					objlist: []
				},
				list2: [],
				poptype: 1, //弹窗类型
				system: {
					w: 0,
					h: 0,
					scale: 1,
					systemScale: 1,
				},
				sel_img_index: 0, //选择当前项
				sel_img_id: 0, //选择当前项
				sel_index: 0, //选择当前项
				sel_ind: 0, //选择当前项
				mark: '',
				showtip: false, //是否显示弹窗1
				showtip2: false, //是否显示弹窗1
				showinput: false,
				content1: '顶部弹 popup',
				type1: '', //弹窗显示方式
				params: {
					id: '',
					company_id: '',
					product_attr_id: [],
					product_coding_id: []
				},
				params2: {
					company_id: '',
					top_id: '',
					type: ''
				},
				json: {
					task_id: 0,
					company_id: 0,
					task_data: []
				},
				sourceType: ['album', 'camera'],
				chooseNum: 9,
				imglist: [], //上传图片-传参-新增图片
				pageType: '',
				popType: '',
				pagedata: {
					company_id: '',
					top_id: '',
					type: ''
				},
			}
		},
		computed: {
			...mapGetters(['companyInfo', 'userInfo']),
			img_width() {
				return (this.system.w - 42) / 3;
			}
		},
		onShow() {
			uni.getSystemInfo().then(res => {
				let system = res[1]
				this.system.scale = 667 / 375 //按照苹果留 375*667比例 其他型号手机等比例缩放 显示
				this.system.systemScale = system.windowWidth / 375 //按照苹果留 375*667比例 其他型号手机等比例缩放 显示
				this.system.w = system.windowWidth;
				this.system.h = system.windowHeight;
			})
			this.getdata2();

		},
		onLoad(option) {
			console.log(222, option)
			this.params.company_id = this.companyInfo.id;
			this.params2.company_id = this.companyInfo.id;
			this.pagedata.company_id = this.companyInfo.id;
			this.json.company_id = this.companyInfo.id;
			if (!!option.title) {
				this.page_title = option.title;
			}
			if (option.id) {
				this.params.id = option.id;
			}
			if (option.pageType) {
				this.pageType = option.pageType;
				this.getdata();
			}
		},
		onNavigationBarButtonTap(e) {
			console.log(123, e)
			if (e.index === 0) {
				if (this.pageType === 'pop') {
					this.content1 = 'center'
					this.type1 = 'bottom';
					this.showtip = !this.showtip;
				} else if (this.pageType === 'prop') {
					this.selImg()
				}
			}
		},
		methods: {
			getdata2() {
				if (this.pageType === 'pop') { //pop
					this.pagedata.top_id = 0;
					this.pagedata.type = 1;
					getProductCodingLists(this.pagedata).then(res => {
						if (res.code === 2000) {
							let pageobj = {
								type: 'radio',
								submenu: [],
							}
							let submenu = {
								type: 'one',
								submenu: [],
							}
							submenu.submenu = res.data;
							if (submenu.submenu && submenu.submenu.length > 0) {
								submenu.submenu.forEach(item => {
									this.$set(item, 'selected', false);
								})
							}
							pageobj.submenu.push(submenu);
							getProductAttrLists(this.pagedata).then(res => {
								if (res.code === 2000) {
									let submenu2 = res.data;
									if (submenu2 && submenu2.length > 0) {
										submenu2.forEach(item2 => {
											this.$set(item2, 'submenu', Array);
											this.$set(item2, 'type', 'two');
											this.pagedata.top_id = item2.id;
											getProductAttrLists(this.pagedata).then(res2 => {
												if (res2.code === 2000) {
													this.$nextTick(() => {
														item2.submenu = res2.data;
														if (item2.submenu && item2
															.submenu.length > 0) {
															item2.submenu.forEach(
																item3 => {
																	this.$set(
																		item3,
																		'selected',
																		false
																		)
																})
														}
													})
												}
											})
										})
									}
									if (submenu2 && submenu2.length > 0) {
										submenu2.forEach(item4 => {
											pageobj.submenu.push(item4);
										})
									}
									this.pageobj = pageobj;
									console.log(555, pageobj)
								}
							})
						}
					})


				} else if (this.pageType === 'prop') { //prop
					this.pagedata.top_id = 0;
					getProductCodingLists(this.pagedata).then(res => {
						if (res.code === 2000) {
							let pageobj = res.data;
							if (pageobj && pageobj.length > 0) {
								pageobj.forEach(item => {
									this.$set(item, 'submenu', Array);
									this.$set(item, 'isOpen', false);
								})
							}
							this.pageobj = pageobj;
						}
					})
				}
			},
			//选择图片
			selImg() {
				let _self = this;
				uni.chooseImage({
					count: this.chooseNum,
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: this.sourceType,
					success: (tempFilePaths) => {

						console.log('选择文件：', tempFilePaths)
						uni.showLoading({
							title: '上传中'
						});
						let uploadImgs = [];
						getOssUploadsParams().then(res => {
							if (res.code === 2000) {
								tempFilePaths.tempFilePaths.forEach((item, index) => {
									uploadImgs.push(new Promise((resolve, reject) => {
										let file_path = item;
										let filename = tempFilePaths.tempFiles[
											index];
										let suffix = "." + _self.getCaption(
											filename.path);
										let file_name = new Date().getTime() + Math
											.random().toString(
												36).substring(3, 20) + suffix
										console.log(333333, file_name, filename)
										//上传图片接口
										uni.uploadFile({
											url: res.data.host,
											filePath: file_path,
											fileType: 'image',
											name: 'file',
											formData: {
												name: file_path,
												'key': res.data.dir +
													file_name,
												'policy': res.data.policy,
												'OSSAccessKeyId': res.data
													.accessid,
												'success_action_status': '200',
												//让服务端返回200,不然，默认会返回204
												'signature': res.data
													.signature,
											},
											success: (res2) => {
												resolve(res2);
												console.log(
													'uploadImage success, res is:',
													res2)
												let img_list = {
													url: ''
												}
												img_list.url = res.data
													.host + '/' + res
													.data.dir +
													file_name;
												_self.imglist.push(
													img_list)
												console.log(666,
													img_list)
											},
											fail: (err) => {
												console.log(err);
												reject(err);
											},
											complete: () => {
												//uni.hideLoading();
											}
										});
									}))
									Promise.all(uploadImgs).then((results) => { //执行所有需请求的接口
											if (index === (tempFilePaths.tempFilePaths
													.length - 1)) {
												if (this.pageType === 'pop') {
													uni.navigateTo({
														url: `/pages/picBook/createTask?task_id=${_self.params.id}&company_id=${_self.params.company_id}&type=2&pageType=pro&addType=popadd&selType=pop&img_list=${JSON.stringify(_self.imglist)}`
													})
												} else if (this.pageType === 'prop') {
													uni.navigateTo({
														url: `/pages/user/batch?task_id=${this.params.id}&pageType=prop&pageStatu=2&userType=system&selType=prop&imglist=${JSON.stringify(_self.imglist)}`
													})
												}
											}
											uni.hideLoading();
										})
										.catch((res3, object) => {
											uni.hideLoading();
										});
								})
							}
						})
					}
				});
			},
			//备注
			edit_remark(sel_img_index, id) {
				this.popType = '1';
				this.showinput = true;
				this.content1 = 'center'
				this.type1 = 'center';
				this.sel_img_id = id;
				this.mark = '';
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach((item, index) => {
						if (sel_img_index === index) {
							if (this.sel_img_id === item.id) {
								this.mark = item.mark;
							}
						}
					})
				}
			},
			resdata2(item) {
				console.log(2222, item)
				this.objdata.flowname = item.title;
				this.objdata.flow_path_id = item.id;
			},
			resdata3(item) {
				console.log(2222, item)
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach((ite, index) => {
						if (this.sel_img_index === index) {
							ite.product_album_data_id = item[0].id;
							ite.url = item[0].url;
							this.$forceUpdate() //二维数组，开启强制渲染
						}
					})
				}
			},
			resdata4() {
				this.getdata();
			},
			getdata() {
				taskDataInfos(this.params).then(res => {
					if (res.code === 2000) {
						this.objdata.title = res.data.title;
						this.objdata.img = res.data.img;
						//this.objdata.objlist = res.data.dataList;
						this.objdata.id = res.data.id;
						this.objdata.type = res.data.type;
						this.objdata.flow_path_id = res.data.flow_path_id;

						/* if (this.objdata.objlist && this.objdata.objlist.length > 0) {
							this.objdata.objlist.forEach(item => { //单个图片
								let datalist = []
								this.$set(item, 'datalist', datalist); //增加一级
								if (item.data && item.data.length > 0) {
									item.data.forEach(item2 => { //图片的属性
										let data = [];
										let texture = [];
										this.$set(item2, 'data', data)
										this.$set(item2, 'checked', true)
										if (item2.top_id === 0) {
											item.datalist.push(item2)
										}
										if (item.datalist && item.datalist.length > 0) {
											item.datalist.forEach(item3 => {
												this.$set(item3, 'texture', texture);
												if (item2.top_id === item3.product_coding_id) {
													item3.data.push(item2)
													item3.texture.push(item2.texture_name)
												}
											})
										}
										if (item.datalist && item.datalist.length > 0) {
											item.datalist.forEach(item3 => {
												if (item3.data && item3.data.length > 0) {
													item3.data.forEach(item4 => {
														if(item3.product_coding_id === item4.top_id){
															item3.texture.push(item4.texture_name) //增加材质
															if (item4.product_coding_id === item2.top_id) {
																console.log(111, item4)
																item4.data.push(item2);
																item3.texture.push(item2.texture_name) //增加材质
															}
														}
													})
												}
											})
										}
									})
								}
							})
						} */

						let objlist = []
						if(res.data.dataList && res.data.dataList.length>0){
							res.data.dataList.forEach(item=>{
								let datalist = []
								this.$set(item, 'datalist', datalist)
								if(item.data && item.data.length>0){
									item.data.forEach(item2=>{
										if (item2.top_id === 0) {
											item.datalist.push(item2)
											let data = [];
											let texture = [];
											this.$set(item2, 'data', data)
											this.$set(item2, 'texture', texture)
											if(item.datalist && item.datalist.length>0){
												item.datalist.forEach(item3=>{
													if (item2.top_id === item3.product_coding_id) {
														item3.data.push(item2)
														item3.texture.push(item2.texture_name)
													}
												})
											}
										}
									})
								}
								if(item.data && item.data.length>0){
									item.data.forEach(item2=>{
										if(item.datalist && item.datalist.length>0){
											item.datalist.forEach(item3=>{
												if (item2.top_id === item3.product_coding_id) {
													item3.data.push(item2)
													item3.texture.push(item2.texture_name)
												}
												if(item3.data && item3.data.length>0){
													item3.data.forEach(item4=>{
														let data = [];
														this.$set(item4, 'data', data)
													})
												}
											})
										}
									})
								}
								if(item.data && item.data.length>0){
									item.data.forEach(item2=>{
										if(item.datalist && item.datalist.length>0){
											item.datalist.forEach(item3=>{
												if(item3.data && item3.data.length>0){
													item3.data.forEach(item4=>{
														if (item2.top_id === item4.product_coding_id) {
															item4.data.push(item2);
															item3.texture.push(item2.texture_name) //增加材质
														}
													})
												}
											})
										}
									})
								}
								objlist.push(item);
							})
						}
						this.objdata.objlist = objlist;
						console.log(44444, this.objdata.objlist)
						//流程
						getFlowLists({
							company_id: res.data.company_id
						}).then(res2 => {
							if (res2.code === 2000) {
								if (res2.data && res2.data.length > 0) {
									res2.data.forEach(item => {
										if (res.data.flow_path_id === item.id) {
											this.objdata.flowname = item.title;
										}
									})
								}
							}
						})
					}
				})
			},
			//跳转pop画册
			toPop() {
				uni.navigateTo({
					url: `/pages/picBook/picBookList?task_id=${this.params.id}&pageType=pro&pageStatu=2&userType=system&selType=pop`
				})
				this.showtip = false;
			},
			//跳转pop画册
			toPop2() {
				uni.navigateTo({
					url: `/pages/picBook/picBookList?task_id=${this.params.id}&pageType=pro&pageStatu=2&userType=system&selType=pop&selNum=one`
				})
				this.showtip2 = false;
			},
			//下弹窗
			photoAlbum() {
				this.selImg()
				this.showtip = false;
			},
			delete_img(sel_img_index, id) {
				console.log(22, sel_img_index, id)
				this.popType = '2';
				this.showinput = true;
				this.content1 = 'center'
				this.type1 = 'center';
				this.sel_img_index = sel_img_index;
			},

			getCaption(obj) {
				var index = obj.lastIndexOf("\.");
				obj = obj.substring(index + 1, obj.length);
				return obj;
			},
			//增加0-级属性
			add_pro(iiii, index, top_id, poptype) {
				console.log(555, index, top_id, poptype)
				console.log(555, this.objdata)
				this.poptype = poptype;
				let _self = this;
				this.sel_img_index = iiii;
				this.sel_index = index;
				if (this.pageType === 'pop') {
					this.params2.type = 1;
				} else if (this.pageType === 'prop') {
					this.params2.type = 2;
				}
				if (this.poptype === '1') {
					this.params2.top_id = 0;
					getProductCodingLists(_self.params2).then(res => {
						if (res.code === 2000) {
							this.list2 = res.data;
							if (this.list2 && this.list2.length > 0) {
								this.list2.forEach(item => {
									this.$set(item, 'checked', false);
									if (this.objdata.objlist && this.objdata.objlist.length > 0) {
										this.objdata.objlist.forEach((item2, i1) => {
											if (iiii === i1) {
												if (item2.datalist && item2.datalist.length > 0) {
													item2.datalist.forEach(item3 => {
														if (item3.checked && item3.name ===
															item.name) {
															item.checked = true
														}
													})
												}
											}
										})
									}
								})
							}
						}
					})
				} else if (this.poptype === '2') {
					this.params2.top_id = top_id;
					getProductCodingLists(_self.params2).then(res2 => {
						if (res2.code === 2000) {
							this.list2 = res2.data;
							if (this.list2 && this.list2.length > 0) {
								this.list2.forEach(item => {
									this.$set(item, 'checked', false);
									if (this.objdata.objlist && this.objdata.objlist.length > 0) {
										this.objdata.objlist.forEach((item2, i2) => {
											if (iiii === i2) {
												if (item2.datalist && item2.datalist.length > 0) {
													item2.datalist.forEach(item3 => {
														if (item3.data && item3.data
															.length > 0) {
															item3.data.forEach((item4,
																i4) => {
																if (item4
																	.checked &&
																	item4.name ===
																	item.name) {
																	item.checked =
																		true
																}
															})
														}
													})
												}
											}
										})
									}
								})
							}
						}
					})
				}
			},
			add_pro2(iiii, index, ind, top_id, poptype) {
				console.log(555, index, ind, top_id, poptype)
				this.poptype = poptype;
				let _self = this;
				this.sel_img_index = iiii;
				this.sel_index = index;
				this.sel_ind = ind;
				this.params2.type = 1;
				if (this.poptype === '3') {
					this.params2.top_id = top_id;
					getProductCodingLists(_self.params2).then(res2 => {
						if (res2.code === 2000) {
							this.list2 = res2.data;
							if (this.list2 && this.list2.length > 0) {
								this.list2.forEach(item => {
									this.$set(item, 'checked', false);
									if (this.objdata.objlist && this.objdata.objlist.length > 0) {
										this.objdata.objlist.forEach((item2, i2) => {
											if (iiii === i2) {
												if (item2.datalist && item2.datalist.length > 0) {
													item2.datalist.forEach(item3 => {
														if (item3.data && item3.data
															.length > 0) {
															item3.data.forEach((item4,
																i4) => {
																if (item4.data &&
																	item4.data
																	.length > 0) {
																	item4.data
																		.forEach((
																			item5,
																			i5
																		) => {
																			if (item5
																				.checked &&
																				item5
																				.name ===
																				item
																				.name
																			) {
																				item.checked =
																					true
																			}
																		})
																}
															})
														}
													})
												}
											}
										})
									}
								})
							}
						}
					})
				}
			},
			//弹窗-下拉框选择
			checks(id, checked) {
				console.log(123, id)
				console.log(5555, this.list2)
				let _self = this;
				if (!checked) {
					if (this.poptype === '1') {
						if (this.list2 && this.list2.length > 0) {
							this.list2.forEach(item => {
								if (item.id === id) {
									item.checked = !checked;
									this.$set(item, 'product_coding_id', item.id);
									this.$set(item, 'delete', 2);
									delete item.id;
									if (this.objdata.objlist && this.objdata.objlist.length > 0) {
										this.objdata.objlist.forEach((item2, ind) => {
											if (this.sel_img_index === ind) {
												item2.datalist.push(item);
												console.log(999, item2.datalist)
												if (item2.datalist && item2.datalist.length > 0) {
													item2.datalist.forEach(item3 => {
														if (item3.data) {

														} else {
															let data = [];
															let texture = []
															this.$set(item3, 'data', data)
															this.$set(item3, 'texture', texture)
														}
													})
												}
											}
										})
									}
								}
							})
						}
					} else if (this.poptype === '2') {
						if (this.list2 && this.list2.length > 0) {
							this.list2.forEach(item0 => {
								if (item0.id === id) {
									item0.checked = !checked;
									this.$set(item0, 'product_coding_id', item0.id);
									this.$set(item0, 'delete', 2);
									delete item0.id;
									if (this.objdata.objlist && this.objdata.objlist.length > 0) {
										this.objdata.objlist.forEach((item, i) => {
											if (i === this.sel_img_index) {

												if (item.datalist && item.datalist.length > 0) {
													item.datalist.forEach((item2, ii) => {
														if (ii === this.sel_index) {
															console.log(3344, item2)
															item2.data.push(item0)
															item2.texture.push(item0.texture_name);
															if (item2.data && item2.data.length >
																0) {
																item2.data.forEach((item3,
																	iii) => {
																	let data = [];
																	if (item2.data.length -
																		1 == iii) {
																		this.$set(item3,
																			'data',
																			data);
																		this.$set(item3,
																			'number', 0
																		);
																	}
																})
															}
														}
													})
												}
											}
										})
									}
								}
							})
						}
					} else if (this.poptype === '3') {
						if (this.list2 && this.list2.length > 0) {
							this.list2.forEach(item0 => {
								if (item0.id === id) {
									item0.checked = !checked;
									this.$set(item0, 'number', 0);
									this.$set(item0, 'product_coding_id', item0.id);
									this.$set(item0, 'delete', 2);
									delete item0.id;
									if (this.objdata.objlist && this.objdata.objlist.length > 0) {
										this.objdata.objlist.forEach((item, i) => {
											if (i === this.sel_img_index) {

												if (item.datalist && item.datalist.length > 0) {
													item.datalist.forEach((item2, ii) => {
														if (ii === this.sel_index) {
															if (item2.data && item2.data.length >
																0) {
																item2.data.forEach((item3,
																	iii) => {
																	if (iii === this
																		.sel_ind) {
																		item3.data.push(
																			item0)
																		item2.texture.push(
																			item0
																			.texture_name
																		);
																	}
																})
															}
														}
													})
												}
											}
										})
									}
								}
							})
						}
					}
				}
				console.log(4444, this.objdata.objlist)
			},
			//材质选择
			choose(index) {
				if (this.list && this.list.length > 0) {
					this.list.forEach((item, ind) => {
						if (ind === index) {
							item.statu = !item.statu
						}
					})
				}
				console.log(11111, this.list)
			},
			//材质弹窗
			sel_mat() {
				if (this.list && this.list.length > 0) {
					this.list.forEach((item, ind) => {
						this.$set(item, 'statu', false);
					})
				}
			},
			//确认材质选择
			confirm_sel(list, index) {
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach((item, i) => {
						if (this.sel_index === i) {
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach((item2, ii) => {
									if (index === ii) {
										item2.texture = list;
									}
								})
							}
						}
					})
				}
			},
			//筛选项
			/* selnum(index) {
				console.log('点击图片', index)
				this.sel_img_index = index;
			}, */
			//删除一级
			delItem(sel_img_index, index, ind) {
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach((item, i) => {
						if (sel_img_index === i) {
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach((item2, ii) => {
									if (index === ii) {
										/* let list = item2.data
										delete list[ind]
										item2.data = list.filter(Boolean) */
										if (item2.data && item2.data.length > 0) {
											item2.data.forEach((item3, iii) => {
												if (ind === iii) {
													item3.delete = 1;
												}
											})
										}
									}
								})
							}
						}
					})
				}

			},
			//删除二级
			delItem2(sel_img_index, index, index2, index3) {
				console.log(1111, sel_img_index, index, index2, index3)
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach((item, i) => {
						if (sel_img_index === i) {
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach((item2, ii) => {
									if (index === ii) {
										if (item2.data && item2.data.length > 0) {
											item2.data.forEach((item3, iii) => {
												if (index2 === iii) {
													if (item3.data && item3.data.length > 0) {
														item3.data.forEach((item4, iiii) => {
															console.log(222222, item4)
															if (index3 === iiii) {
																item4.delete = 1;
															}
														})
													}
													/* let list = item3.data
													delete list[index3]
													item3.data = list.filter(Boolean) */

												}
											})
										}
									}
								})
							}
						}
					})
				}
				console.log(11111, this.objdata.objlist)
			},
			rednum1(sel_img_index, index, index2) {
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach((item, i) => {
						if (sel_img_index === i) {
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach((item2, ii) => {
									if (index === ii) {
										if (item2.data && item2.data.length > 0) {
											item2.data.forEach((item3, iii) => {
												if (index2 === iii) {
													if (item3.number > 0) {
														item3.number -= 1
													}
												}
											})
										}
									}
								})
							}
						}
					})
				}
			},
			addnum1(sel_img_index, index, index2) {
				console.log('一级增加', index, index2)
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach((item, i) => {
						if (sel_img_index === i) {
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach((item2, ii) => {
									if (index === ii) {
										if (item2.data && item2.data.length > 0) {
											item2.data.forEach((item3, iii) => {
												if (index2 === iii) {
													item3.number += 1
												}
											})
										}
									}
								})
							}
						}
					})
				}
			},
			rednum2(sel_img_index, index, index2, index3) {
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach((item, i) => {
						if (sel_img_index === i) {
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach((item2, ii) => {
									if (index === ii) {
										if (item2.data && item2.data.length > 0) {
											item2.data.forEach((item3, iii) => {
												if (index2 === iii) {
													if (item3.data && item3.data.length > 0) {
														item3.data.forEach((item4, iiii) => {
															if (index3 === iiii) {
																if (item4.number > 0) {
																	item4.number -= 1
																}
															}
														})
													}
												}
											})
										}
									}
								})
							}
						}
					})
				}
			},
			addnum2(sel_img_index, index, index2, index3) {
				console.log('二级增加', index, index2, index3)
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach((item, i) => {
						if (sel_img_index === i) {
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach((item2, ii) => {
									if (index === ii) {
										if (item2.data && item2.data.length > 0) {
											item2.data.forEach((item3, iii) => {
												if (index2 === iii) {
													if (item3.data && item3.data.length > 0) {
														item3.data.forEach((item4, iiii) => {
															if (index3 === iiii) {
																item4.number += 1
															}
														})
													}
												}
											})
										}
									}
								})
							}
						}
					})
				}
			},
			//下一步
			confirm() {
				console.log(8888, this.objdata.objlist)
				let past = true;
				if(this.objdata.objlist && this.objdata.objlist.length>0){
					this.objdata.objlist.forEach(item=>{
						if(item.datalist && item.datalist.length>0){
							item.datalist.forEach(item2=>{
								if(item2.data && item2.data.length>0){
									item2.data.forEach(item3=>{
										if(item3.has_next === 0){
											if(item3.number > 0){
												if(item3.width === '0.00' || item3.height === '0.00'){
													console.log(9999, item3)
													uni.showToast({
														title:'请输入已增加数量的产品尺寸！',
														icon:'none',
														duration:2000
													})
													past = false
												}
											}
										}else if(item3.has_next === 1){
											if(item3.data && item3.data.length>0){
												item3.data.forEach(item4=>{
													if(item4.number > 0){
														if(item4.width === '0.00' || item4.height === '0.00'){
															uni.showToast({
																title:'请输入已增加数量的产品尺寸！',
																icon:'none',
																duration:2000
															})
															past = false
														}
													}
												})
											}
										}
									})
								}
							})
						}
					})
				}
				if(past){
					uni.navigateTo({
						url: `/pages/order/PopConfirmOrder?pageType=${this.pageType}&objdata=${JSON.stringify(this.objdata)}`
					})
				}

				/* let _self = this;
				this.json.task_id = this.objdata.id;
				let json = {
					company_id: this.json.company_id,
					title: this.objdata.title,
					type: this.objdata.type,
					img: this.objdata.img,
					flow_path_id: this.objdata.flow_path_id,
					id: this.objdata.id
				}

				editTasks(json).then(res => {
					if (res.code === 2000) {

					}
				})
				let task_datas = [];
				if (this.objdata.objlist && this.objdata.objlist.length > 0) {
					this.objdata.objlist.forEach(item => {
						if(this.pageType === 'pop'){
							let task_data = {
								id: '',
								image_name: '',
								product_album_data_id: '',
								mark: '',
								delete:'',
								data: []
							}
							task_data.id = item.id;
							task_data.image_name = item.image_name;
							task_data.product_album_data_id = item.product_album_data_id;
							task_data.mark = item.mark;
							task_data.delete = item.delete;
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach(item2 => {
									task_data.data.push(item2)
								})
							}
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach(item2 => {
									if (item2.data && item2.data.length > 0) {
										item2.data.forEach(item3 => {
											task_data.data.push(item3)
										})
									}
								})
							}
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach(item2 => {
									if (item2.data && item2.data.length > 0) {
										item2.data.forEach(item3 => {
											if (item3.data && item3.data.length > 0) {
												item3.data.forEach(item4 => {
													task_data.data.push(item4)
												})
											}
										})
									}
								})
							}
							task_datas.push(task_data)
						}else if(this.pageType === 'prop'){
							let task_data = {
								id: '',
								image_name: '',
								url: '',
								mark: '',
								delete:'',
								data: []
							}
							task_data.id = item.id;
							task_data.image_name = item.image_name;
							task_data.url = item.url;
							task_data.mark = item.mark;
							task_data.delete = item.delete;
							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach(item2 => {
									task_data.data.push(item2)
								})
							}

							if (item.datalist && item.datalist.length > 0) {
								item.datalist.forEach(item2 => {
									if (item2.data && item2.data.length > 0) {
										item2.data.forEach(item3 => {
											task_data.data.push(item3)
										})
									}
								})
							}
							task_datas.push(task_data)
						}
						console.log(999, task_datas)
					})
				}
				if (task_datas && task_datas.length > 0) {
					task_datas.forEach(item => {
						if (item.data && item.data.length > 0) {
							item.data.forEach(item2 => {
								delete item2.data;
								delete item2.create_time;
								delete item2.company_id;
								delete item2.delete_time;
								delete item2.name;
								delete item2.next_num;
								delete item2.product_texture_id;
								//delete item2.texture;
								delete item2.type;
								delete item2.update_time;

							})
						}
					})
				}
				this.json.task_data = task_datas
				saveTaskDatas(this.json).then(res => {
					if (res.code === 2000) {
						uni.showToast({
							title: '保存成功！',
							icon: 'none',
							duration: 2000
						})
						this.$util.prePage().resdata();
						setTimeout(() => {
							uni.navigateBack();
						}, 500)
					}
				}) */
			},
			//返回
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			//重置筛选
			resetFilterData() {

			},
			//确认筛选
			setFilterData() {
				let product_attr_id = [];
				let product_coding_id = [];

				if (this.pageobj.submenu && this.pageobj.submenu.length > 0) {
					this.pageobj.submenu.forEach(item => {
						if (item.type === 'one') {
							if (item.submenu && item.submenu.length > 0) {
								item.submenu.forEach(item2 => {
									if (item2.selected) {
										product_coding_id.push(item2.id)
									}
								})
							}
						}
						if (item.type === 'two') {
							if (item.submenu && item.submenu.length > 0) {
								item.submenu.forEach(item2 => {
									if (item2.selected) {
										product_attr_id.push(item2.id)
									}
								})
							}
						}
					})
				}
				console.log(22, product_attr_id, product_coding_id)
				this.params.product_attr_id = product_attr_id;
				this.params.product_coding_id = product_coding_id;
				this.getdata();
			},
			//点击筛选
			selectRadioLabel(index, ind, selected) {
				console.log(11, index, ind, selected)
				if (this.pageobj.submenu && this.pageobj.submenu.length > 0) {
					this.pageobj.submenu.forEach((item, i) => {
						if (item.type === 'one') {
							if (index === i) {
								if (item.submenu && item.submenu.length > 0) {
									item.submenu.forEach((item2, ii) => {
										if (ind === ii) {
											item2.selected = !selected;
										}
									})
								}
							}
						} else if (item.type === 'two') {
							if (index === i) {
								if (item.submenu && item.submenu.length > 0) {
									item.submenu.forEach((item2, ii) => {
										if (ind === ii) {
											item2.selected = !selected;
										} else {
											item2.selected = false;
										}
									})
								}
							}
						}

					})
				}
			},
			loadmore() {

			},
			confirm2() {
				if (this.popType === '1') { //编辑备注
					if (this.objdata.objlist && this.objdata.objlist.length > 0) {
						this.objdata.objlist.forEach((item, index) => {
							if (this.sel_img_id === item.id) {
								item.mark = this.mark;
							}
						})
					}
				} else if (this.popType === '2') { //删除图册图片
					if (this.objdata.objlist && this.objdata.objlist.length > 0) {
						this.objdata.objlist.forEach((item, index) => {
							if (this.sel_img_index === index) {
								item.delete = 1
							}
						})
					}
				}
				this.showinput = false;
				console.log(666, this.objdata.objlist)

			},
			//底部弹窗
			change1(e) {
				if (!e.show) {
					this.showtip = false;
					this.showtip2 = false;
					this.showinput = false;
				}
			},
			//取消
			cancel(type) {
				this['show' + type] = false;
				this.showinput = false;
			},
		}
	}
</script>

<style lang="scss">
	/* 提示窗口 */
	.w-tip2 {
		/* #ifndef APP-NVUE */
		display: flex;
		flex-direction: column;
		/* #endif */
		width: 70vw;
		border-radius: 10rpx;
		background-color: #fff;
		box-shadow: 0rpx 7rpx 7rpx 0rpx rgba(0, 0, 0, 0.1);
		margin: 30rpx auto 0;

		.w-tit {
			font-size: 36rpx;
			font-weight: bold;
			color: $font-color-3;
			line-height: 60rpx;
			height: 60rpx;
			margin-top: 20rpx;
			text-align: center;
		}

		.w-but {
			display: flex;
			font-size: 32rpx;
			font-weight: 400;
			color: $font-color-b3;
			height: 84rpx;
			line-height: 84rpx;

			.w-but-txt {
				flex: 1;
				text-align: center;
				border-right: 1rpx solid #f5f5f5;
			}

			.w-but-txt:last-of-type {
				border-right: none;
			}
		}

		.w-con {
			display: flex;
			text-align: center;
			font-weight: 400;
			padding: 30rpx 30rpx;
			border-bottom: 1rpx solid #f5f5f5;

			.txt-row {
				width: 100%;
				text-align: center;
				font-size: 28rpx;
				color: $font-color-9;
			}

			.txt-input {
				border: 1rpx solid #f5f5f5;
				height: 60rpx;
				width: 100%;
			}
		}
	}

	/* 提示窗口 */
	.w-tip {
		/* #ifndef APP-NVUE */
		display: flex;
		flex-direction: column;
		/* #endif */
		width: 100vw;
		min-height: 200rpx;
		border-radius: 20rpx 20rpx 0px 0px;
		background-color: #fff;
		box-shadow: 0rpx 7rpx 7rpx 0rpx rgba(0, 0, 0, 0.1);
		padding: 20rpx 0rpx;
		margin: 30rpx auto 0;

		.w-con {
			line-height: 100rpx;
			font-size: 32rpx;
			font-weight: 400;
			color: $font-color-3;
			text-align: center;

			.w-con-txt {
				border-bottom: 1rpx solid #f5f5f5;
			}

			.w-con-cen {
				color: #198FFF;
			}
		}
	}

	/* 提示窗口 */
	.w-tip3 {
		/* #ifndef APP-NVUE */
		display: flex;
		flex-direction: column;
		/* #endif */
		width: 100vw;
		min-height: 100rpx;
		border-radius: 20rpx 20rpx 0px 0px;
		background-color: #fff;
		box-shadow: 0rpx 7rpx 7rpx 0rpx rgba(0, 0, 0, 0.1);
		padding: 20rpx 0rpx;
		margin: 30rpx auto 0;

		.w-con {
			line-height: 100rpx;
			font-size: 32rpx;
			font-weight: 400;
			color: $font-color-3;
			text-align: center;

			.w-con-txt {
				border-bottom: 1rpx solid #f5f5f5;
			}

			.w-con-cen {
				color: #198FFF;
			}
		}
	}

	.titleNview-placing {
		height: var(--status-bar-height);
		box-sizing: content-box;
		background: $uni-bg-color;
		display: block;
		position: sticky;
		top: 0rpx;
		z-index: 9999;
		overflow: hidden
	}

	.page-content {
		border-top: 1rpx solid #f5f5f5;
		width: 100vw;
		height: 100%;
		background: $uni-bg-color-grey;

		.page-top {
			display: flex;
			flex-direction: column;
			box-sizing: content-box;
			background: $uni-bg-color;
			display: block;
			position: sticky;
			top: 0rpx;
			z-index: 9999;
			border-bottom: 1rpx solid #f5f5f5;
		}

		.page-body {
			display: flex;
			height: 100%;
			padding: 0;

			.btn-box {
				width: 100%;
				position: fixed;
				left: 0;
				right: 0;
				bottom: 0;
				height: 90rpx;
				display: flex;
				flex-shrink: 0;
				flex-direction: row !important;
				align-items: center;
				font-size: 36rpx;
				line-height: 90rpx;
				color: $font-color-w;
				z-index: 5;

				.submit {
					text-align: center;
					flex: 2;
					background-color: #198FFF;
				}
			}


			.body-box {
				display: flex;
				flex-direction: column;
				background: $uni-bg-color;
				padding-bottom: 40rpx;

			}

		}
	}
</style>
